{{extend "tutorial_layout.html"}}

{{block content_main}}
{{use "jqscrollpagination"}}

<div class="row">
    <div class="pull-right">
        {{if request.user:}}
            <a href="/tutorial/add" class="btn btn-success"><i class="icon icon-plus icon-white"></i>添加新教程</a>
        {{else:}}
            <span>你还没有登录，无法添加新教程！</span>
        {{pass}}
    </div>
</div>
<ul class="unstyled tutorial-list" id="tutorials">
    {{for row in objects:}}
    <li class="tutorial-item clearfix">
        <img src="{{=row.image}}" class="preface pull-left" title="{{=row.title}}"/>
        <h2><a href="/tutorial/read/{{=row.id}}">《{{=row.title}}》</a></h2>
        <span class="gray">由 {{=row.author}} 更新，最后更新时间 {{=row.modified_date}}</span>
        <p>
            {{<< row.summary}}
        </p>
        <div class="turorial-buttons">
            <a href="/tutorial/read/{{=row.id}}" class="btn btn-primary">点击阅读 &raquo;</a>
        </div>
        <div class="tutorial-info">
            <span>访问次数：<a href="#" class="para-comments-count right">{{=row.hits}}</a></span>
            <span>评论：<a href="#" class="para-comments-count right">{{=row.comments_count}}</a></span>
        </div>
    </li>
    {{pass}}
</ul>

<div class="pagination pagination-centered">{{<< pagination}}</div>
<script>
    $(function(){
        $('a.para-comments-count').click(function(e){
            e.preventDefault();
        });
    /*    
        $('#tutorials').scrollpagination({
            total: {{#=total}},
            pageRows : 10,
            initLoad : true,
            onChange: function(page){
                var that = this;
                $('#tutorials .loading').remove();
                $('#tutorials').append('<p style="text-align:center" class="loading"><img src="/static/jqutils/loading.gif"/></p>').fadeIn();
                $.ajax({
                    type:'GET',
                    dataType:'json',
                    url:'/tutorial?page='+page+'&rows='+that.options.pageRows+'&data=',
                    success:function(data){
                        $('#tutorials .loading').fadeOut().remove();
                        $.each(data.rows, function(index, v){
                            var t = template($('#tutorialTemplate').html(), v);
                            $('#tutorials').append(t);
                        });
                    }
                });
            }
            
        });
    */
    });
</script>
{{end}}